package com.zhijian.medical.controller;

import com.zhijian.medical.annotation.Response;
import com.zhijian.medical.entity.po.LocationInsertVo;
import com.zhijian.medical.entity.po.LocationUpdateVo;
import com.zhijian.medical.entity.vo.response.LocationVo;
import com.zhijian.medical.service.LocationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@Api(tags = "设备位置相关")
public class LocationController {


    @Autowired
    private LocationService locationService;

    /**
     * 设备位置新增
     *
     * @return
     */
    @Response
    @PostMapping("/location")
    @ApiOperation("设备位置新增")
    public boolean insertLocation(@RequestBody LocationInsertVo locationVo) {
        return locationService.insert(locationVo);
    }


    /**
     * 设备区域位置修改
     *
     * @return
     */
    @Response
    @PutMapping("/location/{id}")
    @ApiOperation("设备区域位置修改")
    public boolean updateLocation(@PathVariable("id") Long id, @RequestBody LocationUpdateVo locationUpdateVo) {
        locationUpdateVo.setId(id);
        return locationService.updateName(locationUpdateVo);
    }

    /**
     * 设备位置树状数据
     *
     * @return
     */
    @Response
    @GetMapping("/location/tree")
    @ApiOperation("设备位置树状数据")
    public List<LocationVo> locationVoTreeList() {
        return locationService.renderTreeList();
    }


    /**
     * 删除区域
     *
     * @return
     */
    @Response
    @DeleteMapping("/location/{id}")
    @ApiOperation("删除区域")
    public boolean deleteLocation(@PathVariable("id") Long id) {
        return locationService.deleteById(id);
    }
}
